package com.jxchexie.admin;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.jxchexie.signin.R;
import com.ramotion.circlemenu.CircleMenuView;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 管理员界面
 */
public class AdminActivity extends AppCompatActivity {

    private boolean quit = false; //设置退出标识

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_admin);
        final CircleMenuView menu = (CircleMenuView) findViewById(R.id.circle_menu);
        menu.setEventListener(new CircleMenuView.EventListener() {
            @Override
            public void onMenuOpenAnimationStart(@NonNull CircleMenuView view) {
                Log.d("D", "onMenuOpenAnimationStart");
            }

            @Override
            public void onMenuOpenAnimationEnd(@NonNull CircleMenuView view) {
                Log.d("D", "onMenuOpenAnimationEnd");
            }

            @Override
            public void onMenuCloseAnimationStart(@NonNull CircleMenuView view) {
                Log.d("D", "onMenuCloseAnimationStart");
            }

            @Override
            public void onMenuCloseAnimationEnd(@NonNull CircleMenuView view) {
                Log.d("D", "onMenuCloseAnimationEnd");
            }

            @Override
            public void onButtonClickAnimationStart(@NonNull CircleMenuView view, int index) {
                Log.d("D", "onButtonClickAnimationStart| index: " + index);
            }

            @Override
            public void onButtonClickAnimationEnd(@NonNull CircleMenuView view, int index) {
                Log.d("D", "onButtonClickAnimationEnd| index: " + index);
                switch (index) {
                    case 0:
                        startActivity(new Intent(AdminActivity.this,MapActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(AdminActivity.this,SendMessageActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(AdminActivity.this,UnsignedUserActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(AdminActivity.this,modifyNeededInfo.class));
                        break;
                    case 4:
                        startActivity(new Intent(AdminActivity.this,AdminDangerActivity.class));
                        break;
                    case 5:
                        startActivity(new Intent(AdminActivity.this,HolidayAdminActivity.class));
                        break;


                }
            }

            @Override
            public boolean onButtonLongClick(@NonNull CircleMenuView view, int index) {
                Log.d("D", "onButtonLongClick| index: " + index);
                return true;
            }

            @Override
            public void onButtonLongClickAnimationStart(@NonNull CircleMenuView view, int index) {
                Log.d("D", "onButtonLongClickAnimationStart| index: " + index);
            }

            @Override
            public void onButtonLongClickAnimationEnd(@NonNull CircleMenuView view, int index) {
                Log.d("D", "onButtonLongClickAnimationEnd| index: " + index);
            }
        });

    }

    /**
     * 按两次返回键退出
     */
    @Override
    public void onBackPressed() {
        if(quit==false){//询问是否退出程序
            Toast.makeText(AdminActivity.this,"再按一次退出管理员界面",Toast.LENGTH_SHORT).show();
            new Timer(true).schedule(new TimerTask() {
                @Override
                public void run() {
                    quit=false;
                }
            },2000);
            quit=true;
        }else {
            super.onBackPressed();
            finish();
        }
    }

}